{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "metadata": {}
   },
   "outputs": [],
   "source": [
    "from torchvision import transforms\n",
    "from torchvision import datasets\n",
    "\n",
    "train_set = datasets.CIFAR10(root='./datasets', train=True, download=True)\n",
    "test_set = datasets.CIFAR10(root='./datasets', train=False, download=True)\n",
    "\n",
    "print(test_set[0])\n",
    "print(test_set.classes)\n",
    "\n",
    "img, target = test_set[0]\n",
    "\n",
    "print(img)\n",
    "print(target)\n",
    "# img.show()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "metadata": {}
   },
   "outputs": [],
   "source": [
    "# dataloader 使用\n",
    "from torch.utils.tensorboard import SummaryWriter\n",
    "from torch.utils.data import DataLoader, Dataset\n",
    "dataset_tranforms = transforms.Compose([\n",
    "    transforms.ToTensor(),\n",
    "])\n",
    "\n",
    "train_set = datasets.CIFAR10(root='./datasets', train=True, download=True, transform=dataset_tranforms)\n",
    "test_set = datasets.CIFAR10(root='./datasets', train=False, download=True, transform=dataset_tranforms)\n",
    "\n",
    "test_loader = DataLoader(test_set, batch_size=64, shuffle=True, num_workers=0,drop_last=True)\n",
    "\n",
    "\n",
    "writer = SummaryWriter('./logs/dataloader/')\n",
    "\n",
    "step = 0\n",
    "for data in test_loader:\n",
    "    imgs, targets = data\n",
    "    writer.add_image('test_set_loader', imgs, step, dataformats='NCHW')\n",
    "    step += 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "metadata": {}
   },
   "outputs": [],
   "source": [
    "writer.close()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
